package common.interfaces;

import java.sql.SQLException;
import java.util.Collection;

import msg.EventMessage;
import user.User;

import common.exceptions.*;

/**
 * A class whose role it is to manage the persistence of event registrations
 * 
 * @author Gal Lalouche
 */
public interface IEventRegistration extends IPersistent {
	
	/**
	 * Register a user to an event
	 * 
	 * @param user The user to register
	 * @param event The event to register to
	 * @return {@code true} iff the user was not already registered to the event
	 * @throws InvalidUserException If the user is not in the system
	 * @throws InvalidEventException If the event is not in the system
	 * @throws SQLException
	 */
	boolean register(User user, EventMessage event) throws SQLException, InvalidEventException,
			InvalidUserException;
	
	/**
	 * Unregisters a user from an event
	 * 
	 * @param user The user to unregister
	 * @param event The event to unregister
	 * @return {@code true} iff the user was registered to the event and was unregistered successfully
	 * @throws SQLException
	 * @throws InvalidUserException
	 * @throws InvalidEventException
	 */
	boolean unregister(User user, EventMessage event) throws SQLException, InvalidEventException,
			InvalidUserException;
	
	/**
	 * Removes all registrations by a user
	 * 
	 * @param user The user
	 * @throws InvalidUserException If the user does not exist in the system
	 * @throws SQLException
	 */
	void removeAllUserRegisrations(User user) throws SQLException, InvalidUserException;
	
	/**
	 * Removes all registrations to an event
	 * 
	 * @param user The event
	 * @throws InvalidEventException If the event does not exist in the system
	 * @throws SQLException
	 */
	void removeAllEventRegisrations(EventMessage user) throws SQLException, InvalidEventException;
	
	/**
	 * Gets all events registered by a user
	 * 
	 * @param user The user
	 * @return All events that the user registered to
	 * @throws InvalidUserException If the user does not exists in the system
	 * @throws SQLException
	 */
	Collection<EventMessage> getAllEventRegisteredByUser(User user) throws SQLException, InvalidUserException;
	
	/**
	 * Gets all users registered to an event
	 * 
	 * @param event The event
	 * @return All user registered to an event
	 * @throws InvalidEventException If the event does not exists in the system
	 * @throws SQLException
	 */
	Collection<User> getAllUsersRegisteredToEvent(EventMessage event) throws SQLException, InvalidEventException;
	
	/**
	 * Gets the count of the users registered to an event
	 * 
	 * @param event The event
	 * @return The number of users
	 * @throws InvalidEventException If the event does not exists in the system
	 * @throws SQLException
	 */
	int getTotalRegisteredTo(EventMessage event) throws SQLException, InvalidEventException;
	
	/**
	 * @param user The user to check
	 * @param event The event to check
	 * @return <code>true</code> iff the user is registered to the event
	 * @throws InvalidUserException If the user is invalid
	 * @throws InvalidEventException If the event is invalid
	 * @throws SQLException
	 */
	boolean isUserRegisteredToEvent(User user, EventMessage event) throws InvalidUserException,
			InvalidEventException, SQLException;
}
